﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utility;
namespace WebTeamplate
{
    public partial class Admin_PopupBarCode : BasePage
    {
        public string result = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            string id = string.Empty;
            string sl = string.Empty;
            try
            {
                id = Session["idBarCode"].ToString();
            }
            catch
            { 
            }
            try
            {
                sl = Session["slBarCode"].ToString();
            }
            catch
            { 
            }
            if (id != string.Empty && sl != string.Empty)
            {
                List<BarCodeObject> lst = new List<BarCodeObject>();               
                string[] arrId =id.Split(';');
                string[] arrSL = sl.Split(';');
                if (arrId.Length > 1 && arrSL.Length > 1)
                {
                    for (int i = 0; i < arrId.Length; i++)
                    {
                        if (arrId[i].ToString() != string.Empty)
                        {
                            int count = ConvertValueObject.ParseInt(arrSL[i].ToString());
                            if (count < 1)
                                count = 1;
                            for (int k = 1; k <= count; k++)
                            {
                                BarCodeObject objData = new BarCodeObject();
                                objData.ImageUrl = "BarCode/Images/" + arrId[i].ToString() + ".gif";
                                lst.Add(objData);
                            }
                        } 
                    }
                }
                if (lst.Count > 0)
                {
                    //generate form
                    int colum = 3;
                    int columRender = 0;
                    int w = 121;
                    int h = 46;
                    result += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i % colum == 0)
                        {
                            columRender = 1;
                            if (i == 0)
                            {
                                result += @"<tr class='row' style='height:80px'>
                                            <td align='center'>
                                                <img src='" + lst[i].ImageUrl + @"' width='" +w + @"' height='" + h+ @"' />
                                            </td>";
                            }
                            else {
                                result += @"</tr><tr class='row' style='height:80px'>
                                            <td align='center'>
                                                <img src='" + lst[i].ImageUrl + @"' width='" + w + @"' height='" + h + @"' />
                                            </td>";
                            }
                        }
                        else
                        {
                            columRender++;
                            result += @"
                                            <td align='center'>
                                                <img src='" + lst[i].ImageUrl + @"' width='" + w + @"' height='" + h + @"' />
                                            </td>";
                        }
                    }
                    for (int k = 1; k <= (colum-columRender); k++)
                    {
                        result += "<td align='center'>&nbsp;</td>";
                    }
                    result += "</tr></table>";
                }

            }
            
    //        <table border="0" cellpadding="0" cellspacing="0" width="100%">
    //    <tr class="row">
    //        <td align="center">
    //            <img src="BarCode/Images/000000_1.gif" width="121" height="80" />
    //        </td>
    //        <td align="center">
    //            <img src="BarCode/Images/000000_1.gif" width="121" height="80" />
    //        </td>
    //        <td align="center">
    //           <img src="BarCode/Images/000000_1.gif" width="121" height="80" />
    //        </td>
    //    </tr>
    //</table>
        }
     

    }
}
